#include "headers.h"


/* void funcPrism (int v, GLfloat height, GLfloat base[], GLfloat color[]) */
/* { */
/*   int i, k; */
/*   glColor3f(color[0], color[1], color[2]); */

/*   // base inferior */
/*   glPushMatrix(); */
/*   glBegin(GL_POLYGON); */
/*   for (i = 0; i < v; i++) */
/*     glVertex3f(base[3 * i], base[1 + 3*i], base[2 + 3*i]); */
/*   glEnd(); */
/*   glPopMatrix(); */

/*   // base superior */
/*   glPushMatrix(); */
/*   glBegin(GL_POLYGON); */
/*   for (i = 0; i < v; i++) */
/*     glVertex3f(base[3 * i], base[1 + 3*i] + height, base[2 + 3*i]); */
/*   glEnd(); */
/*   glPopMatrix(); */

/*   // lados do prisma */
/*   glPushMatrix(); */
/*   glBegin(GL_POLYGON); */
/*   for (i = 0; i < v; i++) { */
/*     k = (i+1) % v; */
/*     glVertex3f(base[3 * i], base[1 + 3*i], base[2 + 3*i]); */
/*     glVertex3f(base[3 * k], base[1 + 3*k], base[2 + 3*k]); */
/*     glVertex3f(base[3 * k], base[1 + 3*k] + height, base[2 + 3*k]); */
/*     glVertex3f(base[3 * i], base[1 + 3*i] + height, base[2 + 3*i]); */
/*   } */
/*   glEnd(); */
/*   glPopMatrix(); */
/* } */


/*void funcPrism (int v, GLfloat height[], GLfloat base[], GLfloat color[])*/
void funcPrism (int v, GLfloat base[], GLfloat height[])
{
  int i, k;
  GLfloat hX = height[0];  // altura em X
  GLfloat hY = height[1];  // altura em Y
  GLfloat hZ = height[2];  // altura em Z

  //glColor3f(color[0], color[1], color[2]);

  // base inferior
  glPushMatrix();
  glBegin(GL_POLYGON);
  for (i = 0; i < v; i++)
    glVertex3f(base[3 * i], base[1 + 3*i], base[2 + 3*i]);
  glEnd();
  glPopMatrix();

  // base superior
  glPushMatrix();
  glBegin(GL_POLYGON);
  for (i = 0; i < v; i++)
    glVertex3f(base[3 * i] + hX, base[1 + 3*i] + hY, base[2 + 3*i] + hZ);
  glEnd();
  glPopMatrix();

  // lados do prisma
  glPushMatrix();
  glBegin(GL_QUADS);
  for (i = 0; i < v; i++) {
    k = (i+1) % v;
    glVertex3f(base[3 * i], base[1 + 3*i], base[2 + 3*i]);
    glVertex3f(base[3 * k], base[1 + 3*k], base[2 + 3*k]);
    glVertex3f(base[3 * k] + hX, base[1 + 3*k] + hY, base[2 + 3*k] + hZ);
    glVertex3f(base[3 * i] + hX, base[1 + 3*i] + hY, base[2 + 3*i] + hZ);
  }
  glEnd();
  glPopMatrix();
}


void funcDrawParalel (int repet, double width, double length, double height)
{
  glBegin ( GL_QUADS );

  /* Face frontal */
  glNormal3f(0.0, 0.0, 1.0);
  glTexCoord2f(0.0f, 0.0f); glVertex3f(-width/2, -length/2,  height/2);
  glTexCoord2f(repet, 0.0f); glVertex3f( width/2, -length/2,  height/2); 
  glTexCoord2f(repet, repet); glVertex3f( width/2,  length/2,  height/2);
  glTexCoord2f(0.0f, repet); glVertex3f(-width/2,  length/2,  height/2);

  /* Face posterior */
  glNormal3f(0.0, 0.0, -1.0);
  glTexCoord2f(repet, 0.0f); glVertex3f(-width/2, -length/2, -height/2);
  glTexCoord2f(repet, repet); glVertex3f(-width/2,  length/2, -height/2);
  glTexCoord2f(0.0f, repet); glVertex3f( width/2,  length/2, -height/2);
  glTexCoord2f(0.0f, 0.0f); glVertex3f( width/2, -length/2, -height/2);

  /* Face superior */
  glNormal3f(0.0, 1.0, 0.0);
  glTexCoord2f(0.0f, repet); glVertex3f(-width/2,  length/2, -height/2);
  glTexCoord2f(0.0f, 0.0f); glVertex3f(-width/2,  length/2,  height/2);
  glTexCoord2f(repet, 0.0f); glVertex3f( width/2,  length/2,  height/2);
  glTexCoord2f(repet, repet); glVertex3f( width/2,  length/2, -height/2);

  /* Face inferior */
  glNormal3f(0.0, -1.0, 0.0);
  glTexCoord2f(repet, repet); glVertex3f(-width/2, -length/2, -height/2);
  glTexCoord2f(0.0f, repet); glVertex3f( width/2, -length/2, -height/2);
  glTexCoord2f(0.0f, 0.0f); glVertex3f( width/2, -length/2,  height/2);
  glTexCoord2f(repet, 0.0f); glVertex3f(-width/2, -length/2,  height/2);

  /* Face lateral direita */
  glNormal3f(1.0, 0.0, 0.0);
  glTexCoord2f(repet, 0.0f); glVertex3f( width/2, -length/2, -height/2);
  glTexCoord2f(repet, repet); glVertex3f( width/2,  length/2, -height/2);
  glTexCoord2f(0.0f, repet); glVertex3f( width/2,  length/2,  height/2);
  glTexCoord2f(0.0f, 0.0f); glVertex3f( width/2, -length/2,  height/2);

  /* Face lateral esquerda */
  glNormal3f(-1.0, 0.0, 0.0);
  glTexCoord2f(0.0f, 0.0f); glVertex3f(-width/2, -length/2, -height/2);
  glTexCoord2f(repet, 0.0f); glVertex3f(-width/2, -length/2,  height/2);
  glTexCoord2f(repet, repet); glVertex3f(-width/2,  length/2,  height/2);
  glTexCoord2f(0.0f, repet); glVertex3f(-width/2,  length/2, -height/2);
  glEnd();
}


void funcDrawSquareFloor (double side)
{
  glPushMatrix();
  glTranslatef(0.0, -5.0001, 0.0);
  funcDrawParalel(9, side, 10.0, side);
  glPopMatrix();
}

/*
// versao antiga que nao permite textura
void funcDrawSquareFloor (double side)
{
  glPushMatrix();
  //glColor3f(0.5, 0.5, 0.5);
  //glColor3f(1.0, 1.0, 1.0);
  glTranslatef(0.0, -0.0001, 0.0);
  glRotatef(90.0, 1.0, 0.0, 0.0);
  glRectd(-side/2.0, -side/2.0, side/2.0, side/2.0);
  glPopMatrix();
}
*/

void funcShowCoords (double rangeX, double rangeY, double rangeZ)
{
  GLfloat coneBase = 5.0;
  GLfloat h = 20.0;
  int slices = 12;
  int stacks = 9;

  // origem
  glPushMatrix();
  glColor3f(1.0, 1.0, 1.0);
  glutSolidSphere(.05, 50, 50);
  glPopMatrix();

  // eixo X
  glPushMatrix();
  glBegin(GL_LINES);
  glColor3f (1.0, 0.0, 0.0);
  glVertex3f(0.0, 0.0, 0.0);
  glVertex3f(rangeX, 0.0, 0.0);
  glEnd();
  glPopMatrix();

  glPushMatrix();
  glTranslatef(rangeX, 0.0, 0.0);
  glRotatef(90.0, 0.0, 1.0, 0.0);
  glutSolidCone(coneBase, h, slices, stacks);
  glPopMatrix();
  
  // eixo Y
  glPushMatrix();
  glBegin(GL_LINES);
  glColor3f (0.0, 1.0, 0.0);
  glVertex3f(0.0, 0.0, 0.0);
  glVertex3f(0.0, rangeY, 0.0);
  glEnd();
  glPopMatrix();

  glPushMatrix();
  glTranslatef(0.0, rangeY, 0.0);
  glRotatef(-90.0, 1.0, 0.0, 0.0);
  glutSolidCone(coneBase, h, slices, stacks);
  glPopMatrix();

  // eixo Z
  glPushMatrix();
  glBegin(GL_LINES);
  glColor3f (0.0, 0.0, 1.0);
  glVertex3f(0.0, 0.0, 0.0);
  glVertex3f(0.0, 0.0, rangeZ);
  glEnd();
  glPopMatrix();

  glPushMatrix();
  glTranslatef(0.0, 0.0, rangeZ);
  glutSolidCone(coneBase, h, slices, stacks);
  glPopMatrix();
}

